package br.com.servlets;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.List;

import br.com.modelo.RelatoriosDAO;

public class RelatorioController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
	private RelatoriosDAO banco;
	
    public RelatorioController() {
        super();
        banco = new RelatoriosDAO();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String parametro = request.getParameter("acao");
		if (parametro.equals("turma"))
			this.actionRelatorioPorTurma(request, response);
		else
			this.actionRelatorioPorDisciplina(request, response);
	}
	
	private void actionRelatorioPorTurma(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		List relatorio = banco.getRelatorioPorTurma();
		request.setAttribute("relatorioPorTurma", relatorio);
		//Seleciona a p�gina que as informa��es ser�o enviadas
		RequestDispatcher view = request.getRequestDispatcher("/relatorio/estatisticaPorTurma.jsp");
		//Envia e chama a p�gina previamente setada
		view.forward(request, response);
	}

	private void actionRelatorioPorDisciplina(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{
		List relatorio = banco.getRelatorioPorDisciplina();
		request.setAttribute("relatorioPorDisciplina", relatorio);
		//Seleciona a p�gina que as informa��es ser�o enviadas
		RequestDispatcher view = request.getRequestDispatcher("/relatorio/estatisticaPorDisciplina.jsp");
		//Envia e chama a p�gina previamente setada
		view.forward(request, response);
	}

}
